home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / ripdump.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  1KB  |  75 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  * Atari version by David Nash - dnash@chaos.demon.co.uk
  5.  *
  6.  * 29.08.94 DFN - pullentry moved from rip.c for use when RIP is not defined
  7.  *                in config.h
  8.  *
  9.  */
  10.  
  11. #include "global.h"
  12. #include "mbuf.h"
  13. #include "netuser.h"
  14. #include "timer.h"
  15. #include "rip.h"
  16. #include "trace.h"
  17.  
  18. void rip_dump(FILE *fp, struct mbuf **bpp)
  19. {
  20.     struct rip_route entry;
  21.     int i;
  22.     int cmd,version;
  23.     int16 len;
  24.     
  25.     fprintf(fp,"RIP: ");
  26.     cmd = PULLCHAR(bpp);
  27.     version = PULLCHAR(bpp);
  28.     switch(cmd){
  29.     case RIPCMD_REQUEST:
  30.         fprintf(fp,"REQUEST");
  31.         break;
  32.     case RIPCMD_RESPONSE:
  33.         fprintf(fp,"RESPONSE");
  34.         break;
  35.     default:
  36.         fprintf(fp," cmd %u",cmd);
  37.         break;
  38.     }
  39.  
  40.     pull16(bpp);    /* remove one word of padding */
  41.  
  42.     len = len_p(*bpp);
  43.     fprintf(fp," vers %u entries %u:\n",version,len / RIPROUTE);
  44.  
  45.     i = 0;
  46.     while(len >= RIPROUTE){
  47.         /* Pull an entry off the packet */
  48.         pullentry(&entry,bpp);
  49.         len -= RIPROUTE;
  50.  
  51.         if(entry.addr_fam != RIP_IPFAM) {
  52.             /* Skip non-IP addresses */
  53.             continue;
  54.         }
  55.         fprintf(fp,"%-16s%-3u ",inet_ntoa(entry.target),entry.metric);
  56.         if((++i % 3) == 0){
  57.             putc('\n',fp);
  58.         }
  59.     }
  60.     if((i % 3) != 0)
  61.         putc('\n',fp);
  62. }
  63.  
  64.  
  65. void pullentry(struct rip_route *ep, struct mbuf **bpp)
  66. {
  67.     ep->addr_fam = pull16(bpp);
  68.     (void)pull16(bpp);
  69.     ep->target = pull32(bpp);
  70.     (void)pull32(bpp);
  71.     (void)pull32(bpp);
  72.     ep->metric = pull32(bpp);
  73. }
  74.  
  75.